<?php
/**
 * Created by PhpStorm.
 * User: liuwei
 * Date: 2022/12/16
 * Time: 14:19
 */

namespace App\Http\Controllers\Backend1;

use App\Http\Requests\Backend\StrategyRequest;
use App\Services\Business\Models\Faq;
use App\Services\Business\Models\Strategy;
use Doctrine\DBAL\Schema\Schema;
use Illuminate\Http\Request;


class StrategyController extends BaseController
{
 

    public function index(Request $request)
    {

        $strategies  = Strategy::with(['services'])->get();
        return $this->successData(compact('strategies'));
    }
    public function store(StrategyRequest $request, Strategy $strategy){


        $data  =$request->filldata();
        $strategy->fill($data)->save();
        $strategy->services()->attach($data['services']);


        return $this->success("新增方案成功");
    }



    public function detail(Request $request,$id){

        $faq = Faq::query()
            ->where('id',$id)
            ->firstOrFail();
        return $this->successData(compact("faq" ));

    }
  
    public function delete($id)
    {

        $strategy = Strategy::query()->where('id', $id)->firstOrFail();
        $strategy->delete();
        return $this->success(__('删除方案成功'));
    }

    public function mutilDelete(Request $request)
    {
        $ids = (array)$request->input("ids", []);
        if (!$ids){
            return  $this->error(__('参数有错误'));
        }

        //todo 这里要处理班级的一些另外联带关系
        Faq::destroy($ids);
        return $this->success(__('批量删除成功'));
    }


    public  function  update(StrategyRequest $request,$id){
        $faq = Strategy::query()->where('id',$id)->firstOrFail();
        $faq ->fill($request->filldata())->update();
        return  $this->success(__('更新方案成功'));
    }
    public  function  info($id){
        $faq = Faq::query()->where('id',$id)->firstOrFail();
        return  $this->successData(compact('faq'));
    }




}